<?php

namespace App\Admin\Controllers;

use App\Models\Alarm;
use App\Models\MonitorCharge;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Http\Controllers\Controller;

class MonitorAlarmController extends Controller
{
    use HasResourceActions;

    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {

            $content->header('监控报警');
            $content->body($this->grid());
        });
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(Alarm::class, function (Grid $grid) {
            $grid->actions(function ($actions) {
                $actions->disableView();
            });
            $grid->disableExport();
            $grid->disableCreateButton();
            $grid->id('ID')->sortable();
            $grid->title('名称');
            $grid->channel_id('通道号');
            $grid->error('错误码')->label('danger');
            $grid->column('charge','负责人')->display(function (){
                $charge = MonitorCharge::where('scene_id',$this->scene_id)->first();
                return $charge?$charge->name:'';
            });
            $grid->column('phone','联系电话')->display(function (){
                $charge = MonitorCharge::where('scene_id',$this->scene_id)->first();
                return $charge?$charge->phone:'';
            });
        });
    }

}
